<?php
/**
 * 简历管理
 */

class EAdmin_Page_ResumeAutoScore extends EAdmin_Page_Abstract
{
	public function validate(ME_Request $input, ME_Response $output)
	{
		$euserInfo = Libs_EUser::getLoginStatus($input,$output);
		$output->euid =
		$input->euid =
		$euid = $euserInfo[0];

		if(empty($euid)){
			header("location:index.php?c=login");
		}

		return true;
	}
	private function loadDb()
	{
		$this->resumeDb = Db_Resume::instance();
	}

	public function doDefault(ME_Request $input, ME_Response $output)
	{
		$this->loadDb();
		$result = $this->resumeDb->getAll("SHOW TABLES FROM hiall_resume");
		$tables_arr = array();
		foreach($result as $row)
		{
			$row = array_values($row);
			$tables_arr[] = $row[0];
		}
		$output->table_list = $tables_arr;

		$output->setTemplate('ResumeAutoScore');
	}
	

	public function doRuleData(ME_Request $input, ME_Response $output)
	{
		$eid = $input->get("eid");	
		$table_name = $input->get("table_name");	
		$table_f = $input->get("table_f");	

		if($eid == 0){
			echo '<script>alert("参数出错，请重新登录以后再进行评分！");</script>';
			exit;
		}

		$this->loadDb();

		$sql = "select keywords, score from e_score_rule where eid={$eid} and table_name='{$table_name}' and field='{$table_f}' limit 1";
		$score_rule = $this->resumeDb->getRow($sql);
		
		echo json_encode($score_rule);
		exit;
	}

	public function doSaveRuleData(ME_Request $input, ME_Response $output)
	{
		$eid = $input->euid;
		$table_name = $input->post("table_name");
		$field = $input->post("table_fields");
		$keywords = $input->post("keywords");
		$score = $input->post("score");

		$this->loadDb();

		$s_sql = "select id from e_score_rule where eid=$eid and table_name='$table_name' and field='$field' limit 1";
		$rid = $this->resumeDb->getRow($s_sql);

		if(!$rid){
			$sql = "insert into e_score_rule(field, keywords, score, table_name, eid) values ('".$field."','".$keywords."','".$score."','".$table_name."',".$eid.")";
		}else{	
			$sql = "update e_score_rule set keywords='$keywords', score='$score' where eid=$eid and table_name='$table_name' and field='$field'"; 
		}
		$re = $this->resumeDb->query($sql);

		header("location:index.php?c=ResumeAutoScore");
	}

	
}
